package com.mj.hotel.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mj.hotel.R;

public class CustomPagerAdapter extends PagerAdapter {

    private int[] ids = {0,1,2};
    private Context mContext;

    public CustomPagerAdapter(Context context) {
        mContext = context;
    }
    @Override
    public int getCount() {
        return ids.length;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(mContext, R.layout.splash_item_viewpager, null);
        TextView tv = view.findViewById(R.id.splashItem);
        tv.setText("----------" + position + " 页面");
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container,position,object); 这一句要删除，否则报错
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }
}
